﻿using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace TSharp.Core.Test
{
    // the following cref shows how to specify the reference, such that,
    // the compiler will resolve the reference
    /// <summary cref="C{T}">
    /// </summary>
    class A {

        void Test()
        {
            B b = new B();
            C<B> cb = new C<B>();

        }

    
    
    }


    /// <summary>
    /// 
    /// <para>2010/11/3</para>
    /// 	<para>TANGJINGBO</para>
    /// 	<author>tangjingbo</author>
    /// 	<see cref="C{T}"/>
    /// </summary>
    /// 
    class B { }

    /// <summary cref="A">
    /// </summary>
    /// <typeparam name="T"></typeparam>
    class C<T> { }


    public class HandlerA : ICallHandler
    {
        public HandlerA(IUnityContainer container, int order)
        {
            this.container = container;
            this.Order = order;
        }
        private IUnityContainer container
        {
            get;
            set;
        }

        #region ICallHandler 成员

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            Console.WriteLine("调用myhandlerA 开始 " + input.Inputs.Count);
            var ret = getNext().Invoke(input, getNext);
            Console.WriteLine("调用myhandlerA 结束 " + input.Inputs.Count);
            return ret;
        }

        public int Order
        {
            get;
            set;
        }

        #endregion
    }
    public class HandlerB : ICallHandler
    {
        public HandlerB(IUnityContainer container, int order)
        {
            this.container = container;
            this.Order = order;
        }
        private IUnityContainer container
        {
            get;
            set;
        }

        #region ICallHandler 成员

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            Console.WriteLine("调用myhandlerB  开始" + input.Inputs.Count);
            var ret = getNext().Invoke(input, getNext);
            Console.WriteLine("调用myhandlerB 结束" + input.Inputs.Count);
            return ret;
        }

        public int Order
        {
            get;
            set;
        }

        #endregion
    }
    public class HandlerAAttribute : HandlerAttribute
    {
        public override ICallHandler CreateHandler(Microsoft.Practices.Unity.IUnityContainer container)
        {
            return new HandlerA(container, Order);
        }
    }
    public class HandlerBAttribute : HandlerAttribute
    {
        public override ICallHandler CreateHandler(Microsoft.Practices.Unity.IUnityContainer container)
        {
            return new HandlerB(container, Order);
        }
    }
}
